The repository pattern abstracts data access behind a typed interface. Services depend on the interface rather than the ORM directly, making code testable with mock implementations, ORM-agnostic, and easier to change. The interface becomes the contract between the domain layer and the data layer.
Testability — swap the real implementation for a mock by changing one provider in the test module.
ORM independence — switching from TypeORM to Prisma only requires a new IUsersRepository implementation.
Domain clarity — the interface expresses what the domain needs, not what the ORM can do.
Single responsibility — data access logic is isolated from business logic in the service.
Use InjectionToken or a string token as the interface binding key; inject with @Inject('IUsersRepository').